<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  version="2.0"
>

<!-- *******************************************
 common-frame.xsl
 Main Scaffolding common to all pages.
 The xml root element starts processing in here.
********************************************* -->

<!-- **************************
	XSLT general Templates
****************************** -->

<!-- MUST only start with <html> otherwise processing-instruction() will also be copied and this will make IE7 not work properly -->
<xsl:template match="/">
  <xsl:apply-templates select="html"/>
</xsl:template>

<!-- Copy everything in every node -->
<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>

<!-- ***********************************************************************************************
	(THIS IS WHERE ALL THINGS STARTS)
	i.e this xslt grabs the xml file and look for the <html> tag
	and then the content ends up in this template where the whole transformation process begins.
 *************************************************************************************************** -->
<xsl:template match="html">
  <!-- Normal html tag processing -->
  <!-- ie. Start building the final HTML page for the browser starting from DTD declaration -->
  <!-- DTD declaration -->
<!--
<xsl:text disable-output-escaping="yes">
<![CDATA[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
]]>
</xsl:text>
-->

  <!-- html tag -->
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
    <!-- wriite version as xml comment -->
    <xsl:comment>Version: <xsl:value-of select="$version" /></xsl:comment>
    <!-- Process head even if it does not exist in the source page -->
    <xsl:if test="head">
      <xsl:apply-templates select="head"/>
    </xsl:if>
    <xsl:if test="not(head)">
      <xsl:call-template name="default-head"/>
    </xsl:if>
    <!-- Process body -->
    <xsl:apply-templates select="body" />
  </html>
</xsl:template>


<!-- *********
	HTML HEAD
 ************* -->
<xsl:template name="default-head">
  <head>
   <title><xsl:value-of select="$default-page-title" /></title>
   <!-- The following is filled in automatically when I use xsl:output method="html"
     <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1"></meta>
   -->
   <xsl:call-template name="common-head-meta"/>
   <xsl:apply-templates select="meta" />

   <link type="text/css" rel="stylesheet" href="{$main-css-url}"/>
   <xsl:apply-templates select="link" />

   <!-- ONE-STOP-SHOP: compliance patch for microsoft browsers -->
   <xsl:text disable-output-escaping="yes">
     <![CDATA[
       <!-- compliance patch for microsoft browsers -->
				<!--[if lt IE 7]>
					<script src="../js/IE7/2.0(beta3)/IE7.js" type="text/javascript" ></script>
					<script src="../js/IE7/2.0(beta3)/ie7-squish.js" type="text/javascript" ></script>
				<![endif]-->
			]]>
		</xsl:text>
	</head>
</xsl:template>

<!--
    <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript" ></script>
    <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/ie7-squish.js" type="text/javascript" ></script>
-->

<xsl:template match="head">
	<head>
		<!-- Use default title page if there is none on the source page -->
		<xsl:if test="not(title)" >
			<title><xsl:value-of select="$default-page-title" /></title>
		</xsl:if>

		<!-- META Tags -->
    <!-- The following is filled in automatically when I use xsl:output method="html"
         <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1"></meta>
    -->
    <xsl:call-template name="common-head-meta"/>
    <xsl:call-template name="page-head-meta"/>
		<xsl:apply-templates select="meta" />

		<!-- LINK Tags -->
		<link type="text/css" rel="stylesheet" href="{$main-css-url}"/>
		<xsl:call-template name="page-head-link"/>
		<xsl:apply-templates select="link" />

		<!-- Put in the IE 7 standard js to take care of all IE bugs in the box model, so that it should behave same as W3C requirement -->
		<!-- This is the simplest solution without the need to do any Box Model Hack (quite lean too) -->
		<!-- ONE-STOP-SHOP: compliance patch for microsoft browsers -->
		<xsl:text disable-output-escaping="yes">
			<![CDATA[
				<!-- compliance patch for microsoft browsers -->
				<!--[if lt IE 7]>
					<script src="../js/IE7/2.0(beta3)/IE7.js" type="text/javascript" ></script>
					<script src="../js/IE7/2.0(beta3)/ie7-squish.js" type="text/javascript" ></script>
				<![endif]-->
			]]>
		</xsl:text>

		<!-- Apply templates excluding some nodes. These nodes have already been taken care of above -->
		<xsl:apply-templates select="*[not(meta|link)]" />

	</head>
</xsl:template>


<!-- *******
	META
 *********** -->
<xsl:template match="meta">
	<!-- copy all meta tags from source xml files as-is -->
	<xsl:copy>
	  <xsl:apply-templates select="node()|@*" />
	</xsl:copy>
</xsl:template>


<!-- *******
	LINK
 *********** -->
<xsl:template match="link">
	<!-- copy all link tags from source xml files as-is -->
	<xsl:copy>
		<xsl:apply-templates select="node()|@*" />
	</xsl:copy>
</xsl:template>


<!-- ********
	HTML BODY
 ************ -->
<xsl:template match="body">
	<body style="{@style}" >
    <!-- header -->
    <xsl:call-template name="body-common-header"/>
    <div id="body-container">
      <xsl:call-template name="body-left-panel"/>
      <xsl:call-template name="body-right-sidebar"/>
      <xsl:call-template name="body-main-content"/>
    </div>
    <!-- footer -->
    <xsl:call-template name="body-common-footer"/>
	</body>
</xsl:template>


<xsl:template name="body-common-header">
  <xsl:call-template name="common-header-snipplet"/><!-- Common to all pages header detail -->
</xsl:template>

<xsl:template name="body-common-footer">
  <xsl:call-template name="common-footer-snipplet"/><!-- Common to all pages footer detail -->
</xsl:template>

<xsl:template name="body-left-panel">
  <!-- START left-panel -->
  <div id="left-panel">
    <xsl:call-template name="page-left-panel"><!-- Page specific left panel detail -->
		  <xsl:with-param name="page_uid" select="ancestor::html/@page_uid"/>
    </xsl:call-template>
  </div><!-- END left-panel -->
</xsl:template>

<xsl:template name="body-right-sidebar">
  <!-- START of YOUR right-sidebar -->
  <div id="r-sidebar">
    <xsl:call-template name="page-right-sidebar"/><!-- Page specific right sidebar detail -->
  </div>
  <!-- END of YOUR right-sidebar -->
</xsl:template>

<xsl:template name="body-main-content">
  <!-- START main-content -->
  <div id="main-content">
    <xsl:call-template name="page-main-content"/><!-- Page specific main content detail -->
  </div>
  <!-- END of YOUR main-content -->
</xsl:template>

<!-- ****************
	PAGE-MAIN-CONTENT
 ******************** -->
<xsl:template name="page-main-content">
	<!-- Simply copy all tags from source xml files as-is -->
	<!-- ie. copy everything as-is within <body> tag -->
	<xsl:copy>
		<xsl:apply-templates select="node()|@*" />
	</xsl:copy>
</xsl:template>


<!-- ********************************
  Include an xml file for processing
  *********************************** -->
<xsl:template match="include">
  <xsl:variable name="_doc" select="document(@url)/*" />
  <xsl:choose>
    <xsl:when test="string(@element)">
    	<xsl:apply-templates select="$_doc/@element" />
    </xsl:when>
    <xsl:otherwise>
    	<xsl:apply-templates select="$_doc" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ************* -->
</xsl:stylesheet>